package com.lefull.lefullbase.utils.OkGoHelper;


import java.util.HashMap;
import java.util.Map;

/**
 * @author captainteemo
 * @version 1
 * @since 22/05/2018.
 */
public class HTTPClientConfig {
    private String baseUrl = null;
    private ParserBaseModel parserBaseModel;
    private Map<Integer, String> errorMap = new HashMap<>();
    private InitInterface initInterface;
    private static HTTPClientConfig instance = null;

    private HTTPClientConfig() {
    }

    public static HTTPClientConfig getInstance() {
        if (instance == null) {
            synchronized (HTTPClientConfig.class) {
                if (instance == null) {
                    instance = new HTTPClientConfig();
                }
            }
        }
        return instance;
    }

//    public void init(String baseUrl, Map<Integer, String> errorMap) {
//
//    }

    public void init(String baseUrl,ParserBaseModel parserBaseModel, InitInterface callback)
    {
        if (this.baseUrl != null) {
            return;
        }
        this.errorMap = callback.getErrorMap();
        this.baseUrl = baseUrl;
        this.parserBaseModel = parserBaseModel;
        this.initInterface = callback;
    }

//    public void init(String baseUrl) {
//        HashMap<Integer, String> defaultErrorMap = new HashMap<>();
//        defaultErrorMap.put(-2, "呀，网络正在开小差！");
//
//        this.init(baseUrl, defaultErrorMap);
//    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public Map<String, String> getHeaders() {

        if (initInterface.getHeader().isEmpty()){
            return new  HashMap();
        }
        return initInterface.getHeader();
    }

    public ParserBaseModel getParserBaseModel() {
        return parserBaseModel;
    }

    public Map<Integer, String> getErrorMap() {
        return errorMap;
    }
}
